package com.origin.onlinesys.web.controllers.modules.interviewsys;

import com.origin.onlinesys.common.controllers.BaseController;
import com.origin.onlinesys.domain.modules.interviewsys.Situations;
import com.origin.onlinesys.service.modules.interviewsys.impl.SituationsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Administrator on 2015/1/25 0025.
 * 情况说明
 */
@Controller
@RequestMapping(value = "/management/situation")
public class SituationController extends BaseController {
    @Autowired
    private SituationsServiceImpl service;

    @RequestMapping(value = "/findAll")
    public @ResponseBody
    List<Situations> findAll(){
        Situations situ = new Situations();
        situ.setState("1");
        return service.selectByWhere(situ);
    }

    @RequestMapping(value = "/findByWhere")
    public @ResponseBody
    List<Situations> findByWhere(@ModelAttribute Situations sit){
        return service.selectByWhere(sit);
    }

    @RequestMapping(value = "/findByStateY")
    public @ResponseBody
    List<Situations> findByStateY(){
        return service.selectByState("1");
    }

    @RequestMapping(value = "/findById")
    public @ResponseBody
    Situations findById(String id){
        return service.selectById(id);
    }

    @RequestMapping(value = "/add")
    public @ResponseBody
    Situations addSit(@ModelAttribute Situations sit){
        Situations bean = null;
        if(sit.getId() != null){
            service.updateSituations(sit);
            bean = sit;
        }else{
            bean = service.insertSituations(sit);
        }
        return bean;
    }

    @RequestMapping(value = "/update")
    public void updateSit(@ModelAttribute Situations sit){
        service.updateSituations(sit);
    }

    @RequestMapping(value = "/del")
    public @ResponseBody
    String deleteSit(String id){
        service.deleteSituations(id);
        return "1";
    }
}
